package com.ruoyi.project.kbjz.service.impl;

import com.ruoyi.project.kbjz.domain.KbjzRegister;
import com.ruoyi.project.kbjz.domain.vo.KbjzVoCondition;
import com.ruoyi.project.kbjz.mapper.KbjzRegisterMapper;
import com.ruoyi.project.kbjz.service.IKbjzRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Random;

@Service
public class KbjzRegisterServiceImpl implements IKbjzRegisterService {
    @Autowired
    private KbjzRegisterMapper kbjzRegisterMapper;
    @Override
    public int addRegister(KbjzRegister kbjzRegister) {
        //设置挂号编号，当前时间+随机数（1000——9999）+患者性别编号
        Date date = new Date();
        int random = new Random().nextInt(9000)+1000;
        String registerId = "GH"+date.getTime()+random;
        kbjzRegister.setRegisterId(registerId);
        int hours = date.getHours();
        if (hours< 12){
            kbjzRegister.setRegisterPotime(1);
        }else{
            kbjzRegister.setRegisterPotime(2);
        }
        kbjzRegister.setRegisterStatus(0);
        return kbjzRegisterMapper.addRegister(kbjzRegister);
    }

    @Override
    public List<Long> getDeptIdByRegisterCondition(KbjzRegister kbjzRegister) {
        return kbjzRegisterMapper.selectDeptIdByRegister(kbjzRegister);
    }

    @Override
    public List<KbjzRegister> selectRegisterByVoCondition(KbjzVoCondition condition) {
        return kbjzRegisterMapper.selectRegisterByCondition(condition);
    }

    @Override
    public boolean updateRegisterStatus(int registerStatus, String registerId) {
        return kbjzRegisterMapper.updateRegisterStatus(registerStatus, registerId) > 0;
    }

    @Override
    public boolean updateRegisterUserId(Long userId, String registerId) {
        return kbjzRegisterMapper.updateRegisterUserId(userId,registerId) > 0;
    }
}
